package com.sairobo.admin.modules.srblive.manager.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sairobo.base.common.constant.QueryConts;
import com.sairobo.base.common.entity.Page;
import com.sairobo.base.common.entity.Query;
import com.sairobo.admin.modules.srblive.entity.LiveXcxCourses;
import com.sairobo.admin.modules.srblive.dao.LiveXcxCoursesMapper;
import com.sairobo.admin.modules.srblive.manager.LiveXcxCoursesManager;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author admin
 * @email sairobo
 * @url www.sairobo.com
 * @date 2018年1月22日 上午11:48:30
 */
@Component("liveXcxCoursesManager")
public class LiveXcxCoursesManagerImpl extends ServiceImpl<LiveXcxCoursesMapper,LiveXcxCourses> implements LiveXcxCoursesManager {
    
	@Override
	public List<LiveXcxCourses> listLiveXcxCourses(Page<LiveXcxCourses> page, Query search) {
        EntityWrapper<LiveXcxCourses> ew=new EntityWrapper<LiveXcxCourses>();
        //搜索条件
        Map map = (HashMap)search.get(QueryConts.SEARCH_KEYWORD);
        String key = (String) map.get("key");
        //ew.like(true,"XXX",(String) map.get("key"));
        //ew.eq(true,"XXX",(String) map.get("key"));

        //if(StringUtils.isNotEmpty(key)){
        //   ew.andNew();
        //   ew.like(true,"nickName",key);
        //   ew.or();
        //   ew.like(true,"province",key);
        //   ew.or();
        //   ew.like(true,"city",key);
        //}

        // and (a like '%keyword%' or b like '%keyword%')
        ew.andNew();
        ew.like("title",key);
        ew.or();
        ew.like("summary",key);
         ew.or();
        ew.like("subtitle",key);

        ew.orderBy("id",false);
        //ew.orderBy("create_time",false);
        return baseMapper.selectPage(page,ew);
	}

	@Override
	public int saveLiveXcxCourses(LiveXcxCourses liveXcxCourses) {
        return baseMapper.insert(liveXcxCourses);
	}

	@Override
	public LiveXcxCourses getLiveXcxCoursesById(Long id) {
        LiveXcxCourses test = baseMapper.selectById(id);
        return test;
	}

	@Override
	public int updateLiveXcxCourses(LiveXcxCourses liveXcxCourses) {
        return baseMapper.updateById(liveXcxCourses);
	}

	@Override
	public int batchRemove(Long[] id) {
        int count = baseMapper.deleteBatchIds(Arrays.asList(id));
        return count;
	}

    @Override
    public LiveXcxCourses getLiveXcxCoursesByCId(String cid) {
        EntityWrapper<LiveXcxCourses> ew=new EntityWrapper<LiveXcxCourses>();
        ew.eq("cid",cid);
        List<LiveXcxCourses> liveXcxCourses = baseMapper.selectList(ew);
        return CollectionUtils.isEmpty(liveXcxCourses)?null:liveXcxCourses.get(0);
    }
}
